package com.tanhua.sso.controller;

import com.tanhua.sso.service.UserInfoService;
import com.tanhua.sso.service.UserService;
import com.tanhua.sso.vo.ErrorResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: 浩克
 * @date: Created in 2021/2/20 20:06
 */
@RestController
@RequestMapping("user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;
    
    /** 
     * @description:完善个人基本信息
     * @param param
     * @param token
     * @return
     */
    @RequestMapping("loginReginfo")
    public ResponseEntity<Object> saveUserInfo(@RequestBody Map<String, String> param,
                                               @RequestHeader("Authorization")String token){
        try {
            boolean bool = this.userInfoService.saveUserInfo(param,token);
            if (bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        String msg = "保存用户信息失败!";
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage(msg).build();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }

    /**
     * @description:完善个人信息---用户头像
     * @param file
     * @param token
     * @return
     */
    @RequestMapping("loginReginfo/head")
    public ResponseEntity<Object> saveUserLogo(@RequestParam("headPhoto") MultipartFile file,
                                               @RequestHeader("Authorization")String token){
        try {
            Boolean bool = this.userInfoService.saveUserLogo(file,token);
            if (bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        String msg = "保存用户Logo失败!";
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage(msg).build();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }
}
